Crate guess_host_triple
source ·Expand description
Guess which Rust-supported platform is running the current code.
§Introduction
In the world of compilers, for both Rust and other languages, the “host” is the computer where the compiler runs and produces an executable, and the “target” is the computer where the resulting executable runs. Usually they are the same, but they don’t have to be; for example, you can use a powerful desktop computer to compile code for a tiny microcontroller that wouldn’t have the resources to compile a program on its own.
For compilers that can target many different kinds of computers, each target is given a unique name according to the “target triple” convention. If we describe the computer that the compiler runs on with a “triple”, that’s a “host triple”.
Before you can install a copy of the Rust compiler on a given computer, you need to know the host triple Rust uses to describe computer, so you can choose a compatible one. This crate provides a function that guesses the host triple for the computer that it runs on, which you can look up in the Rust release channel metadata to find the URLs of the packages you’ll need to download.
The code in this crate was originally extracted from the official rustup tool.
§Example
extern crate guess_host_triple;
guess_host_triple::guess_host_triple()
.map(|triple| println!("This computer's triple: {}", triple))
.unwrap_or_else(|| println!("Can't guess this computer's triple"));
// Prints something like:
//
// This computer's triple: x86_64-unknown-linux-gnu
Functions§
- Guess which Rust-supported platform is running the current code.